package com.freesky.web.manager.controller.panel;

import com.freesky.common.dao.entity.PanelContent;
import com.freesky.common.pojo.DataTablesResult;
import com.freesky.common.pojo.ZTreeNode;
import com.freesky.common.utils.reponse.JSONResponse;
import com.freesky.web.manager.remote.panel.HomePanelContentRemote;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 陈玉林
 * @modifiedBy:
 * @date: Create In 8:54 2018/12/13
 * @description:
 */
@Controller
@Api(description = "首页板块内容管理")
public class HomePanelContentController {
    @Autowired
    private HomePanelContentRemote remote;

    @ApiOperation(value = "进入界面-首页版块内容列表")
    @GetMapping(  "/home/panel/content/page")
    public String page() {
        return "home-panel-content/list";
    }

    @ApiOperation(value = "进入界面-首页版块内容添加")
    @GetMapping(value =  "/home/panel/content/add/page")
    public String addPage(){
        return "home-panel-content/add";
    }

    @ApiOperation(value = "进入界面-首页版块内容选择关联商品")
    @GetMapping(value =  "/home/panel/content/choose-item/page")
    public String chooseItemPage(){
        return "home-panel-content/choose-item";
    }
    @ApiOperation(value = "进入界面-首页版块内容编辑")
    @GetMapping(value =  "/home/panel/content/update")
    public String update(){
        return "home-panel-content/update";
    }


    @ResponseBody
    @GetMapping(value = "/home/panel/content/tree/list")
    @ApiOperation(value = "获取不包含轮播图的板块树列表")
    public List<ZTreeNode> treeList(){
        return remote.treeList();
    }

    @ResponseBody
    @GetMapping(value = "/home/panel/content/list/{panelId}")
    @ApiOperation(value = "通过panelId获得板块内容列表")
    public DataTablesResult list(@PathVariable("panelId") int panelId){
        return remote.list(panelId);
    }
    @ResponseBody
    @PostMapping(value =   "/home/panel/content/add")
    @ApiOperation(value = "首页版块内容添加")
    public JSONResponse addContent(@ModelAttribute PanelContent panelContent) {
        return remote.add(panelContent);
    }
    @ResponseBody
    @DeleteMapping(value =   "/home/panel/content/del/{ids}")
    @ApiOperation(value = "删除内容分类")
    public JSONResponse delete(@PathVariable(value = "ids")  int[] ids){
        return remote.delete(ids);
    }


    @ResponseBody
    @PostMapping(value = "/home/panel/content/update")
    @ApiOperation(value = "编辑板块内容")
    public JSONResponse update(@ModelAttribute PanelContent panelContent){
        return remote.update(panelContent);
    }

}
